<?php
/**
 * Created by PhpStorm.
 * User: Powerless
 * Date: 2017-4-21
 * Time: 14:15
 */

namespace app\star\controller;

use cmf\controller\HomeBaseController;
use think\Request;
use qcos\Cos;

class PersonalController extends HomebaseController
{
    public function postData()
    {
        $url = input("post.url");
        $data = Request::instance()->post('data/a');
        if($url && $data){
            $this->httpPost(HTTP_WEB.$url,$data);
        }
    }
    public function hostPage()
    {
        return $this->fetch("hostPage");
    }

    public function modify()
    {
        $this->assign("spost", HTTP_WEB);
        $this->assign("simgs", HTTP_IMG.VERSION_LIVESTAR.'/Default/');
        $this->assign("rtime", RUNTIME_PATH.'img/');
        return $this->fetch("modify");
    }

    // 用户头像上传
    public function uploadImg()
    {
        $file = $_FILES['img'];
        $root = VERSION_LIVESTAR.'/Default/';
        $pathName['path'] = date('Y/m/');
        $pathName['name'] = microtime (true)*10000;
        $path = $root.$pathName['path'];
        $cos = new Cos();
        $type = pathinfo($file["name"]);
        $info = $cos->upload($file["tmp_name"],$path.$pathName['name'].'.'.$type['extension']);
        if($info){
            $data['code'] = 1;
            $data['msg'] = '上传成功';
            $data['data'] = ['path' => $pathName['path'],'file' => $pathName['name'].'.'.$type['extension']];
        }else{
            $data['code'] = 0;
            $data['msg'] = '上传错误';
            $data['data'] = [];
        }
        return json_encode($data);
    }

}